package com.drools.demo.server;

import com.drools.demo.entity.Logistics;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author czq
 * @Package com.drools.demo.server
 * @Date 2024/8/26 16:43
 * @description:
 */
@Service
public class DroolsService {
    private final KieContainer kieContainer;

    @Autowired
    public DroolsService(KieContainer kieContainer) {
        this.kieContainer = kieContainer;
    }

    public Logistics calculate(Logistics logistics) {
        KieSession kieSession = kieContainer.newKieSession();
        kieSession.insert(logistics);
        kieSession.fireAllRules();
        kieSession.dispose();
        return logistics;
    }
}
